package fserv.control;

import fserv.entities.Command;
import fserv.entities.FileProposition;
import fserv.entities.Reply;
import fserv.ni.CtrlToNI;
import fserv.ni.NIToCtrl;

/**
 *
 * @author arthur
 */
public class ServerController implements NIToCtrl {

	private static ServerController instance = null;

	/**
     * Reference to the Network Interface.
     */
    protected CtrlToNI ni;
    
    /**
     * Thread in which the Network Interface is running.
     */
    protected Thread niThread;
    
    /**
     * Constructor for the Controller.
     */

	private ServerController() {}

	public static ServerController getInstance() {
		if(ServerController.instance == null) 
			ServerController.instance = new ServerController();
		return ServerController.instance;
	}

	public void setNI(CtrlToNI ni) {
		this.ni = ni;
	}
	
	@Override
	public void replyReceived(Reply rep) {
		throw new UnsupportedOperationException("Server shouldn't receive replies");
	}

	@Override
	public void commandReceived(Command cm) {
    CommandRunner runner = new CommandRunner(ni, cm);
    runner.start();
	}

	@Override
	public void filePropositionReceived(FileProposition fp) {
		throw new UnsupportedOperationException("Not supported yet.");
	}
	
}
